#!/bin/sh
########################################################################
# Begin fcron
#
# Description : Fcron cron init script
#
# Author      : Name - name@linuxfromscratch.org
#
# Version     : BLFS 7.0
#
########################################################################

### BEGIN INIT INFO
# Provides:            fcron
# Required-Start:      $local_fs $network $syslog
# Should-Start:        networkmanager wicd
# Required-Stop:       $local_fs $network $syslog
# Should-Stop:         networkmanager wicd
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts fcron.
# Description:         Starts fcron daemon.
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/init-functions

#$LastChangedBy: dj $
#$Date: 2019-09-08 13:50:13 -0500 (Sun, 08 Sep 2019) $

case "$1" in
   start)
      log_info_msg "Starting OPENVPN Torrent..."
        modprobe tun
	/usr/sbin/openvpn --config /etc/pia/US\ Denver.ovpn --writepid /run/openvpn-torrent.pid --daemon
	sh /media/Scripts/mail_me.sh "OPENVPN Torrent is up"
      evaluate_retval
      ;;

   stop)
      log_info_msg "Stopping OPENVPN-Torrent..."
      PID_FILE=$(cat /run/openvpn-torrent.pid)
      kill -9 $PID_FILE
      rm -rf /run/openvpn-torrent.pid
      sh /media/Scripts/mail_me.sh "OPENVPN Torrent is down"
      evaluate_retval
      ;;

   restart)
      $0 stop
      sleep 1
      $0 start
      ;;

   status)
      if [ -f /run/openvpn-torrent.pid ]; then
          PID_FILE=$(cat /run/openvpn-torrent.pid)
          echo "OPENVPN Torrent is running on process:" $PID_FILE
      else
          echo "OPENVPN Torrent is not running."
      fi
      ;;

   *)
      echo "Usage: $0 {start|stop|restart|status}"
      exit 1
      ;;
esac

# End /etc/init.d/fcron
